package com.oocl.homework.format;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

import com.oocl.homework.format.command.CommandProcessor;
import com.oocl.homework.format.command.CommandProcessorImpl;




public class NetworkController {
	
	
	public void action() throws Exception{
		ServerSocket server = new ServerSocket(8888);
		Socket socket = server.accept();
		OutputStream out = socket.getOutputStream();
		InputStream in = socket.getInputStream();
		BufferedReader reader = new BufferedReader(new InputStreamReader(in));
		String str = "";
		CommandProcessor commandProcessor = new CommandProcessorImpl();
		while ((str = reader.readLine())!=null) {
			System.out.println(str);
			String result = commandProcessor.process(str);
			System.out.println(str);
			out.write(result.getBytes());
		}
		
		
		
		
		
	}
	
	
	public static void main(String[] args) throws Exception{
		new NetworkController().action();
	}

}
